package com.hailong.zyt.intercepter;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Slf4j
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object object = session.getAttribute("userType");
        if(object != null) {
            return true;
        }
        else {
            log.info("未登录，拦截的请求是：{}", request.getRequestURI());
            request.getRequestDispatcher("/").forward(request, response);
            return false;
        }
    }
}
